package com.ruoyi.waterManagement.controller;

import java.math.BigDecimal;
import java.util.*;
import java.io.IOException;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.business.waterManagement.WrStatvolY;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.business.BusinessUtils;
import com.ruoyi.common.datascope.annotation.DataScope;
import com.ruoyi.waterManagement.domain.vo.RzsWrStatvolHwrVO;
import com.ruoyi.waterManagement.domain.vo.WaterReportVO;
import com.ruoyi.waterManagement.service.IWaterRegimeMonitoringService;
import com.ruoyi.waterManagement.service.IWrStatvolHService;
import com.ruoyi.waterManagement.service.IWrStatvolYService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 测站年水量数据Controller
 * 
 * @author hwd
 * @date 2023-02-20
 */
@RestController
@RequestMapping("/WrStatvolY")
public class WrStatvolYController extends BaseController
{
    @Autowired
    private IWrStatvolYService wrStatvolYService;

    @Autowired
    private IWrStatvolHService wrStatvolHService;

    @Autowired
    private IWaterRegimeMonitoringService waterRegimeMonitoringService;
    /**
     * 查询测站年水量数据列表
     */
    @RequiresPermissions("waterManagement:WrStatvolY:list")
    @GetMapping("/list")
    public TableDataInfo list(WrStatvolY wrStatvolY)
    {
        startPage();
        List<WrStatvolY> list = wrStatvolYService.selectWrStatvolYList(wrStatvolY);
        if (list.size()>0){
            String statNm= waterRegimeMonitoringService.queryStatNm(wrStatvolY.getStatCd());
            list.forEach(WrStatvolY->WrStatvolY.setStatNm(statNm));
        }
        return getDataTable(list);
    }

    /**
     * 导出测站年水量数据列表
     */
    @RequiresPermissions("waterManagement:WrStatvolY:export")
    @Log(title = "测站年水量数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WrStatvolY wrStatvolY)
    {
        List<WrStatvolY> list = wrStatvolYService.selectWrStatvolYList(wrStatvolY);
        ExcelUtil<WrStatvolY> util = new ExcelUtil<WrStatvolY>(WrStatvolY.class);
        util.exportExcel(response, list, "测站年水量数据数据");
    }
    /**
     * 导出水管机构年报
     */
    @RequiresPermissions("waterManagement:WrStatvolD:export")
    @Log(title = "导出水管机构年报", businessType = BusinessType.EXPORT)
    @PostMapping("/exportYearWaterReport")
    public AjaxResult exportYearWaterReport(HttpServletResponse response, WaterReportVO waterReportVO) throws IOException {
        if (waterReportVO.getOrgNm()==null){
            return AjaxResult.error("请选择水管机构");
        }
        wrStatvolYService.exportYearWaterReport(waterReportVO, response);
        return AjaxResult.success("1");
    }

    /**
     * 获取测站年水量数据详细信息
     */
    @RequiresPermissions("waterManagement:WrStatvolY:query")
    @GetMapping(value = "/{statCd}")
    public AjaxResult getInfo(@PathVariable("statCd") String statCd)
    {
        return success(wrStatvolYService.selectWrStatvolYByStatCd(statCd));
    }

    /**
     * 新增测站年水量数据
     */
    @RequiresPermissions("waterManagement:WrStatvolY:add")
    @Log(title = "测站年水量数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WrStatvolY wrStatvolY)
    {
        return toAjax(wrStatvolYService.insertWrStatvolY(wrStatvolY));
    }

    /**
     * 修改测站年水量数据
     */
    @RequiresPermissions("waterManagement:WrStatvolY:edit")
    @Log(title = "测站年水量数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WrStatvolY wrStatvolY)
    {
        return toAjax(wrStatvolYService.updateWrStatvolY(wrStatvolY));
    }

    /**
     * 删除测站年水量数据
     */
    @RequiresPermissions("waterManagement:WrStatvolY:remove")
    @Log(title = "测站年水量数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{statCds}")
    public AjaxResult remove(@PathVariable String[] statCds)
    {
        return toAjax(wrStatvolYService.deleteWrStatvolYByStatCds(statCds));
    }

    /**
     * 查询水管机构水量年报
     */
    @GetMapping("/listYearWaterReport")

    public AjaxResult listYearWaterReport(WaterReportVO yearWaterReportVO){

        return AjaxResult.success(wrStatvolYService.selectYearWaterReport(yearWaterReportVO));
    }
}
